<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|Lorem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lorem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-0 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">L|orem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|L^orem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-1 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lo|rem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lo^rem <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-2 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lor|em <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lor^em <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-3 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lore|m <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lore^m <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-4 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem| <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lorem^ <span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-5 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">|Lorem ^<span style="direction: rtl">ipsum dolor sit</span> amet</div>',
  `${behavior} 1-6 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">i|psum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|i^psum dolor sit</span> amet</div>',
  `${behavior} 1-7 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ip|sum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ip^sum dolor sit</span> amet</div>',
  `${behavior} 1-8 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ips|um dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ips^um dolor sit</span> amet</div>',
  `${behavior} 1-9 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsu|m dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ipsu^m dolor sit</span> amet</div>',
  `${behavior} 1-10 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum| dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ipsum^ dolor sit</span> amet</div>',
  `${behavior} 1-11 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">|ipsum ^dolor sit</span> amet</div>',
  `${behavior} 1-12 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum d|olor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |d^olor sit</span> amet</div>',
  `${behavior} 1-13 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum do|lor sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |do^lor sit</span> amet</div>',
  `${behavior} 1-14 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dol|or sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |dol^or sit</span> amet</div>',
  `${behavior} 1-15 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolo|r sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |dolo^r sit</span> amet</div>',
  `${behavior} 1-16 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor| sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |dolor^ sit</span> amet</div>',
  `${behavior} 1-17 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor |sit</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum |dolor ^sit</span> amet</div>',
  `${behavior} 1-18 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor s|it</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor |s^it</span> amet</div>',
  `${behavior} 1-19 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor si|t</span> amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor |si^t</span> amet</div>',
  `${behavior} 1-20 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span>| amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor |sit^</span> amet</div>',
  `${behavior} 1-21 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> |amet</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor |sit</span> ^amet</div>',
  `${behavior} 1-22 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> a|met</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> |a^met</div>',
  `${behavior} 1-23 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> am|et</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> |am^et</div>',
  `${behavior} 1-24 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> ame|t</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> |ame^t</div>',
  `${behavior} 1-25 rtl right word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> amet|</div>',
  selection => selection.modify('extend', 'right', 'word'),
  '<div contenteditable dir="rtl">Lorem <span style="direction: rtl">ipsum dolor sit</span> |amet^</div>',
  `${behavior} 1-26 rtl right word`);
}
</script>
